package com.zzyy.study;

import java.lang.invoke.VarHandle;
import java.math.BigDecimal;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @auther zzyy
 * @create 2024-04-16 14:36
 */
public class ThreadPoolDemoV1
{
    static ThreadPoolExecutor threadPool = new ThreadPoolExecutor(
            5,
            10,
            1L,
            TimeUnit.SECONDS,
            new ArrayBlockingQueue<>(10),r -> {
                Thread t = new Thread(r);
                t.setUncaughtExceptionHandler((x,e) -> {
                    e.printStackTrace();
                    System.out.println("----------come exception");
                });
                return t;
    });

    public static void main(String[] args)
    {
        BigDecimal bigDecimal = new BigDecimal("9.89");

        try {
            threadPool.execute(() -> {
                int age = 10/0;
            });
        } finally {
            threadPool.shutdown();
        }


        /*try
        {
            for (int i = 0; i < 5; i++) {
                int finalI = i;
                threadPool.execute(() -> {
                    if(finalI == 3)
                    {
                        int age = 10/0;
                    }
                    System.out.println(Thread.currentThread().getName()+"\t"+"----come in");
                });
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            threadPool.shutdown();
        }*/
    }
}
